<!-- 提现管理 -->
<template>
  <div>
    <van-row class="cash_contenr">
      <van-col span="8" class="tac">
        <p class="amt red">{{common.formatAmount(amtData.balanceAmt,2)}}</p>
        <p>可提现(USDT)</p>
      </van-col>
      <van-col span="8" class="tac">
        <p class="amt red">{{common.formatAmount(amtData.cashedAmt,2)}}</p>
        <p>已提现(USDT)</p>
      </van-col>
      <van-col span="8" class="tac">
        <p class="amt red">{{common.formatAmount(amtData.freezeBalanceAmt,2)}}</p>
        <p>未结算(USDT)</p>
      </van-col>
    </van-row>

    <van-row class="cash_contenr">
      <van-col span="24">
        <p>输入提现金额(USDT)</p>
        <van-field v-model="cashData.applyAmt" @change="changeInput($event)" type="number" ref="applyAmt" placeholder="请输入金额" />
      </van-col>
    </van-row>
    <van-row class="cash_contenr">
      <van-col span="24">
        <p class="cash_title">提现方式</p>
        <p class="cash_content">根据币种输入您的收款地址，确保信息准确，以您提交的信息为准。</p>
        <textarea v-model="cashData.cashAdd" :row="5" ref="cashAdd" placeholder="请输入收款地址" class="cash_input" />
        <van-row type="flex" justify="center">
          <van-col span="9">
            <van-button type="info" size="small" :loading="loading" loading-text="加载中..." @click="withdrawal">提交申请</van-button>
          </van-col>
        </van-row>
      </van-col>
    </van-row>
    <van-row class="cash_contenr">
      <van-col span="24">
        <p class="cash_title">提现扣除手续费{{getCashValue}}%</p>
        <p class="cash_content">本次提现将扣除手续费(USDT){{poundage?poundage:''}}</p>
        <p class="cash_content">本次提现实际到账金额(USDT){{bookValue?bookValue:''}}</p>
      </van-col>
    </van-row>
    <van-row>
      <div class="contact" @click="$router.push('/contactCustomer')">
				<p class="contact_text"><van-icon name="service" /></p>
        <p class="contact_text">联系客服</p>
      </div>
    </van-row>
  </div>
</template>

<script>
export default {
  data () {
    return {
      cashData: {
        applyAmt: '',
        cashAdd: '',
      },
      getCashValue: '',
      loading: false,
      amtData: '',//可用余额		
      poundage: '',//手续费
      bookValue: '',//到账金额
    }
  },
  methods: {
    changeInput (e) {
      let amt = e.target.value
      this.poundage = Number(amt / this.getCashValue / 100)
      this.bookValue = amt - this.poundage
    },
    //提现
    async withdrawal () {
      if (this.cashData.applyAmt == '') {
        this.$notify({ type: 'warning', message: '提现金额不能为空' });
        this.$refs.applyAmt.focus();
        return;
      }
      if (this.cashData.applyAmt < 0) {
        this.$notify({ type: 'warning', message: '提现金额不能为负数' });
        return;
      }
      if (this.cashData.applyAmt > this.amtData.balanceAmt) {
        this.$notify({ type: 'warning', message: '提现金额不能大于可提现金额' });
        return;
      }
      if (this.cashData.cashAdd == '') {
        this.$notify({ type: 'warning', message: '收款地址不能为空' });
        this.$refs.cashAdd.focus();
        return;
      }
      this.loading = true
      const url = '/cash/save'
      let result = await this.request.mobileRequest('POST', url, this.cashData)
      if (result.code == 200) {
        this.$notify({ type: 'success', message: result.msg });
        this.loading = false
        this.$router.go(-1)
      } else {
        this.loading = false
        this.$notify({ type: 'warning', message: result.msg });
      }
    }
  },
  async created () {
    this.amtData = JSON.parse(localStorage.getItem('userData'))
    this.cashData.cashAdd = this.amtData.cashAdd
    this.getCashValue = await this.common.cashList('CASH_FEE_RATE') * 100
  }
};
</script>

<style scoped>
.cash_contenr {
  padding: 0.3rem;
  border-bottom: 0.01rem solid #d9d9d9;
  background-color: #fff;
}
.amt {
  font-size: 0.55rem;
}
.cash_input {
  width: 100%;
  padding: 0.2rem;
  box-sizing: border-box;
  border: none;
  border: 0.02rem solid #d9d9d9;
  border-radius: 0.1rem;
  margin: 0.4rem 0rem;
}
.cash_title {
  margin-bottom: 0.3rem;
}
.cash_content {
  font-size: 0.28rem;
  letter-spacing: 0.01rem;
  line-height: 0.5rem;
  padding-left: 0.3rem;
}
.contact {
  position: fixed;
  right: 4%;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 50%;
  background-color: #e8bb57;
  color: #555;
  margin-top: 0.2rem;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  box-shadow: 0px 2px 5px rgba(0, 0, 0, 0.349019607843137);
}
.contact_text {
  font-size: 0.3rem;
}
.contact_text i {
  font-size: 0.4rem;
}
.tac p {
  line-height: 0.8rem;
}
.contact_text {
  font-size: 0.3rem;
}
.contact_text i {
  font-size: 0.4rem;
}
</style>
